package cn.lg.soar.redis.config;

import cn.lg.soar.common.data.msg.I18n;
import cn.lg.soar.common.exceptions.BaseCException;
import cn.lg.soar.common.model.HttpResult;
import cn.lg.soar.core.handler.ex.ErrorResult;
import cn.lg.soar.core.handler.ex.SoarExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.PoolException;

/**
 * 全局拦截异常处理异常
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Slf4j
@Configuration
public class RedisExceptionHandleConfig extends SoarExceptionHandler {

    static {
        SoarExceptionHandler.register(PoolException.class, exception -> {
            PoolException e = (PoolException) exception;
            log.error("redis链接失败", e);
            return new ErrorResult(502, HttpResult.fail(new BaseCException(200, I18n.build("redis链接失败"))));
        });
    }

    /**
     * 初始化
     */
    public static void init() {}
}
